from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time


# 初始化浏览器
driver = webdriver.Chrome(ChromeDriverManager().install())
# 最大化浏览器
driver.maximize_window()
# 打开百度
driver.get("https://www.baidu.com")
time.sleep(3)

# 查找百度一下按钮
baidu_button = driver.find_element(By.ID, "su")

# # 存储动作链
# action_1 = ActionChains(driver).context_click(baidu_button)
# # 执行动作链
# action_1.perform()
#
# # 鼠标悬停到【设置】
# setting_button = driver.find_element(By.ID, "s-usersetting-top")
# ActionChains(driver).move_to_element(setting_button).perform()

input_ele = driver.find_element(By.ID, "kw")
# 输入坚果
input_ele.send_keys("坚果")
time.sleep(1)
# 删除-果
input_ele.send_keys(Keys.BACKSPACE)
time.sleep(1)
# 输入空格
input_ele.send_keys(Keys.SPACE)
time.sleep(1)
# 输入python
input_ele.send_keys("python")
time.sleep(1)
# 全选
input_ele.send_keys(Keys.CONTROL, 'a')
time.sleep(1)
# 剪切
input_ele.send_keys(Keys.CONTROL, 'x')
time.sleep(1)
# 粘贴5次
for i in range(5):
    input_ele.send_keys(Keys.CONTROL, 'v')
    time.sleep(1)

time.sleep(5)
driver.quit()